package com.jt.www.biz.order_pc.controller;

import com.jt.www.biz.order_pc.service.SdCheckService;
import com.jt.www.enums.ResultEnum;
import com.jt.www.model.reps.GenericResponse;
import com.jt.www.model.reps.ResultDTO;
import com.jt.www.model.sdcard.SdBankCardEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @Description: 山东投保校验
 * @author: xuxinku
 * @Date: 2019/6/14 19:02
 * @ModifiedDate：
 * @Copyright:江泰保险股份有限公司
 */
@Api(value = "山东投保时校验接口", tags = {"CHECKINSURED-INFO-API"}, description = "山东投保时校验接口")
@RestController
@RequestMapping(value = "/check")
public class CheckInsureController {

    public static final Logger log = LoggerFactory.getLogger(CheckInsureController.class);
    @Autowired
    private SdCheckService sdCheckService;


    /**
     * 山东投保时校验
     *
     * @param holderName 用户usercode
     * @param startDate  投保起期
     * @return
     */
    @ApiOperation(value = "山东险种投保单重复性校验", httpMethod = "GET")
    @GetMapping(value = "/sdCheck", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseEntity checkInsure(@ApiParam(value = "投保人名称", required = true) @RequestParam(value = "holderName") String holderName,
                                      @ApiParam(value = "被保人名称", required = true) @RequestParam(value = "insuredName") String insuredName,
                                      @ApiParam(value = "保单开始时间", required = true) @RequestParam(value = "startDate") Date startDate) {


        try {
            return sdCheckService.checkInsure(holderName, insuredName, startDate);
        } catch (Exception e) {
            e.printStackTrace();
            return GenericResponse.ng(e.getMessage());
        }

    }

    /**
     * 查询卡号
     *
     * @param appCode 根据投保单号查询银行卡号列表
     * @return
     */
    @ApiOperation(value = "根据投保单号查询银行卡号", httpMethod = "GET")
    @GetMapping(value = "/queryBankCards", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultDTO checkInsure(@ApiParam(value = "投保单号", required = true) @RequestParam(value = "appCode") String appCode) {


        if (StringUtils.isEmpty(appCode)) {
            log.error("投保单号不能为空");
            return new ResultDTO(ResultEnum.PARAM_ERROR, "参数不能为空");
        }
        List<SdBankCardEntity> insuredUserInfoEntities = sdCheckService.queryBankCard(appCode);
        return new ResultDTO(ResultEnum.SUCCESS, insuredUserInfoEntities);

    }


}
